package com.example.controller;

import com.example.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

@Controller
public class RegisterController {

    @RequestMapping("/register")
    public String register(@RequestParam String username, @RequestParam String password, RedirectAttributes model){
        model.addAttribute("username", username);
        model.addAttribute("token", "1231213");
        User user =new User(username, password);
        // 注意，是"addFlashAttribute()"而不是addAttribute()
        model.addFlashAttribute("user", user);
        return "redirect:/login/{username}";
    }
}
